package main

//最后访问时间案例
import (
	"fmt"
	"github.com/gin-gonic/gin"
	"time"
)

func indexk(c *gin.Context) {

	// 获取cookie
	lastVist, _ := c.Cookie("lastVist")
	fmt.Println("lastVist", lastVist)

	// 设置cookie
	now := time.Now().String()[:19]
	c.SetCookie("lastVist", now, 100, "/", "127.0.0.1", false, true)

	c.HTML(200, "index.html", gin.H{
		"lastVist": lastVist,
	})

}

func main() {
	r := gin.Default()
	// 返回一个html页面
	r.LoadHTMLGlob("templates/*")
	r.GET("/index", indexk)
	r.Run() // 监听并在 0.0.0.0:8080 上启动服务
}
